package com.yssw.customer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.common.annotation.Anonymous;
import com.yssw.customer.domain.District;
import com.yssw.customer.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.customer.domain.UserMessage;
import com.yssw.customer.service.IUserMessageService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 用户留言管理Controller
 * 
 * @author yssw
 * @date 2023-03-28
 */
@Anonymous
@RestController
@RequestMapping("/customer/message")
public class UserMessageController extends BaseController
{
    @Autowired
    private IUserMessageService userMessageService;

    @Autowired
    private DistrictService districtService;

    /**
     * 查询用户留言管理列表
     */
//    @PreAuthorize("@ss.hasPermi('customer:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserMessage userMessage)
    {
        startPage();
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        return getDataTable(list);
    }

    @GetMapping("address/{parent}")
    public List<District> address(@PathVariable("parent") Long parent){
        List<District> data = districtService.getByParent(parent);
        return data;
    }

    /**
     * 导出用户留言管理列表
     */
//    @PreAuthorize("@ss.hasPermi('customer:message:export')")
    @Log(title = "用户留言管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserMessage userMessage)
    {
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        ExcelUtil<UserMessage> util = new ExcelUtil<UserMessage>(UserMessage.class);
        util.exportExcel(response, list, "用户留言管理数据");
    }

    /**
     * 获取用户留言管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('customer:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userMessageService.selectUserMessageById(id));
    }

    /**
     * 新增用户留言管理
     */
//    @PreAuthorize("@ss.hasPermi('customer:message:add')")
    @Log(title = "用户留言管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserMessage userMessage)
    {
        return toAjax(userMessageService.insertUserMessage(userMessage));
    }

    /**
     * 修改用户留言管理
     */
//    @PreAuthorize("@ss.hasPermi('customer:message:edit')")
    @Log(title = "用户留言管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserMessage userMessage)
    {
        return toAjax(userMessageService.updateUserMessage(userMessage));
    }

    /**
     * 删除用户留言管理
     */
//    @PreAuthorize("@ss.hasPermi('customer:message:remove')")
    @Log(title = "用户留言管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userMessageService.deleteUserMessageByIds(ids));
    }
}
